import 'dart:async';
import 'package:flutter/material.dart';
import '../widgets/dialog/tip_dialog.dart';

class DialogPage extends StatelessWidget {
  const DialogPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Dialog Page')),
      body: DialogContent(),
    );;
  }
}

class DialogContent extends StatefulWidget {
  DialogContent({Key? key}) : super(key: key);

  @override
  State<DialogContent> createState() => _DialogContentState();
}

class _DialogContentState extends State<DialogContent> {
  //
  Widget _buildItem(String name, VoidCallback callback) {
    return GestureDetector(
      onTap: callback,
      child: ListTile(
        title: Text(name),
      ),
    );
  }
  //
  @override
  Widget build(BuildContext context) {
    return ListView(
      children: [
        _buildItem("Loading Type Tip Dialog", () async {
          TipDialogHelper.loading("Loading");
          await new Future.delayed(new Duration(seconds: 5));
          TipDialogHelper.dismiss();
        }),
        new Divider(),
        _buildItem("Success Type Tip Dialog", () async {
          TipDialogHelper.success("Loaded Successfully");
        }),
        new Divider(),
        _buildItem("Fail Type Tip Dialog", () async {
          TipDialogHelper.fail("Load Failed");
        }),
        new Divider(),
        _buildItem("Info Type Tip Dialog", () async {
          TipDialogHelper.info("Do Not Repeat");
        }),
        new Divider(),
        _buildItem("Only Icon Tip Dialog", () async {
          TipDialogHelper.show(new TipDialog(
            type: TipDialogType.SUCCESS,
          ));
        }),
        new Divider(),
        _buildItem("Only text Tip Dialog", () async {
          TipDialogHelper.show(new TipDialog(
            type: TipDialogType.NOTHING,
            tip: "Do Not Repeat",
          ));
        }),
        new Divider(),
        _buildItem("Custom Icon Tip Dialog", () async {
          TipDialogHelper.show(new TipDialog.customIcon(
            icon: new Icon(
              Icons.file_download,
              color: Colors.white,
              size: 30.0,
              textDirection: TextDirection.ltr,
            ),
            tip: "Download",
          ));
        }),
        new Divider(),
        _buildItem("Custom Body Tip Dialog", () async {
          TipDialogHelper.show(new TipDialog.builder(
            bodyBuilder: (context) {
              return new Container(
                width: 120.0,
                height: 90.0,
                alignment: Alignment.center,
                child: new Text(
                  "Custom",
                  style: new TextStyle(color: Colors.white),

                  /// if TipDialogContainer are outside of MaterialApp,
                  /// here is a must to set
                  textDirection: TextDirection.ltr,
                ),
              );
            },
            color: Colors.blue.withAlpha(150),
          ));
        }),
        new Divider(),
      ],
    );
  }
}